interface IAjaxParams {
  [key: string]: any;
}

export default function request(
  url: string,
  params?: IAjaxParams,
  method?: string | undefined
): Promise<any> {
  return new Promise((resolve: Function, reject: Function) => {
    if (method == undefined) {
      fetch(url, {
        method: "GET",
      })
        .then((resp) => resp.json())
        .then((data) => {   // data.ICoupon
          resolve(data);
        });
    } else {
      fetch(url, {
        method,
        headers: {
          "content-type": "application/x-www-form-urlencoded",
        },
        body: params as BodyInit, // 断言
      }).then((data) => {
        resolve(data);
      });
    }
  });
}
